function AddInfo(sInf) {
   //document.getElementById("TestInfo").value += sInf + "\r";
   // document.getElementById("TestInfo").scrollTop = document.getElementById("TestInfo").scrollHeight;

}

//////////////////////////////////////////////////
//函数与方法
//////////////////////////////////////////////////

//连接服务器
function ec_Connect(host) {
    try {
        document.getElementById("jtdrv1").EC_Connect(host);

    } catch (e) {
        AddInfo("连接服务器出错！！");
    }
}

function ec_DisConnect() {
    try {
        document.getElementById("jtdrv1").EC_DisConnect();
    } catch (e) {
        AddInfo("断开服务器连接出错！！");
    }
}

function ec_DownLoadFile(filePath,targetPath){
	filePath = filePath.replace("/","\\");
	targetPath = targetPath.replace("/","\\");
    if(document.getElementById("jtdrv1").EC_DownLoadFile(filePath, targetPath)){
    	alert("下载后文件位置："+targetPath);
    	return;
    }
    alert("下载失败！请重新下载");
    
    //AddInfo("下载后的文件是："+targetPath);
}

//播放录音
function ec_PlayFile(path) {
    try{
	    document.getElementById("jtdrv1").EC_PlayFile(path);
    }catch(e){
    	alert(e.description);
    	return false;
    }
	return true;
}

//停止播放
function ec_PlayStopFile() {
    document.getElementById("jtdrv1").EC_PlayStop();
}


function ec_StartMonitor() {
    document.getElementById("jtdrv1").EC_StartMonitor(document.getElementById("lbxMonitorCh").value);
}

function ec_StopMonitor() {
    document.getElementById("jtdrv1").EC_StopMonitor();
}

function ec_SoftDialOut() {
    document.getElementById("jtdrv1").EC_SoftDialOut(document.getElementById("txtLocal").value, document.getElementById("txtRemote").value);
}

function ec_StopSoftDialOut() {
    document.getElementById("jtdrv1").EC_StopSoftDialOut(document.getElementById("txtLocal").value);
}

function ec_SetLoginInfo() {
    document.getElementById("jtdrv1").EC_SetLoginInfo(document.getElementById("txtUser").value, document.getElementById("txtPassWord").value);
}

function ec_SetLimitedTel() {
    document.getElementById("jtdrv1").EC_SetLimitedTel(document.getElementById("txtLimitedUser").value, document.getElementById("txtLimitedNum").value);
}

//////////////////////////////////////////////////
//事件与消息
//////////////////////////////////////////////////
function OnConnect(sHost) {
    AddInfo("连接成功：" + sHost);
}

function OnDisConnect(sHost) {
    AddInfo("Warning!连接断开：" + sHost);
}


function OnCallIn(s1, s2) {
    AddInfo(s1 + " 来电：" + s2);
    //fPopUpCallCstDlg(s1, s2);
    //检查是否是当前线路
    if (checkLine(s1)) {
    	//来电弹屏显示
        //openIframe2("frmCallIn.aspx?phone=" + s2, "来电显示");
        $("#span_phone").text(s2);
        MobileCT.getAddress(s2,function(entity){
		     $("#city").text(entity.city);
			 $("#cardtype").text(entity.cardtype);
		});
        addTab('客户来电','customer/customer.do?op=toAdd&mobilePhone='+s2);
        
        //document.getElementById("rightFrame").src = "right.aspx?date=" + new Date();
    }
}

//检查是否是当前线路
function checkLine(line) {
    var currtLine = top_lines;
    var lines = currtLine.split(',');

    var flag = 0;
    for (var i = 0; i < lines.length; i++) {
        if (lines[i] == line)
        {
            flag++;
         }
    }

    if (flag > 0) {
        return true;
    }

    return false;
}

function OnCallOut(s1, s2) {
    AddInfo(s1 + " 拨出号码：" + s2);
    
}

function OnRecFile(s1, s2, sDT, iIO, iLen) {
    AddInfo(s1 + " 形成录音文件：" + s2 + "," + sDT + "," + iIO + "," + iLen);

    //s1 来电线路
    if (checkLine(s1)) {
    	
    	$.ajax({
		  type: "POST",
		  url: 'customer/customer.do?op=toAdd&phone=phone&state=1&videoFile='+s2+'&mobilePhone='+iLen,
		  success: function(html){
		    	
		  }

		});
    }
}

function OnNoAnswer(s1, s2) {
    AddInfo(s1 + " 未接来电：" + s2);
    if (checkLine(s1)) {
    	//先保存未接来电,然后显示在右边
        //index.SaveNoAnswer(s1, s2);
        //document.getElementById("rightFrame").src = "right.aspx?date=" + new Date();
        
        $.ajax({
		  type: "POST",
		  url: 'customer/customer.do?op=toAdd&phone=phone&state=0&mobilePhone='+s2,
		  success: function(html){

		  }

		});
    }
}

function OnLeaveMessage(s1, s2, sDT, iLen) {
    AddInfo(s1 + " 留言文件：" + s2 + "," + sDT + "," + iLen);
    
    //document.getElementById("txtPlay").value = s2
}

function OnHookOff(s1, s2) {
    //AddInfo(s1 + " 摘机：" + s2);
    //showDivJt();
}

function OnHookOn(s1, s2) {
    //AddInfo(s1 + " 挂机：" + s2);
}

function OnRing(s1, s2) {
    //AddInfo(s1 + " 振铃：" + s2);
}

function OnTransOut(s1, s2, s3) {
    AddInfo(s1 + " 转其他电话：From:" + s2 + "->" + s3);
}

function fPopUpCallCstDlg(s1, s2) {
    var retval = window.showModalDialog("PopupForm.HTML", window, "dialogWidth=500px;dialogHeight=400px;status=yes");
}